package org.getOffer.offer04;

/**
 * @Author: wjy
 * @Date: 2021/9/26 10:31
 */
public class Solution {

    public static void main(String[] args) {
        
        int[][] arrays = {{1,   4,  7, 11, 15}
                        ,{2,   5,  8, 12, 19}
                        ,{3,   6,  9, 16, 22}
                        ,{10, 13, 14, 17, 24}
                        ,{18, 21, 23, 26, 30}};

        /*System.out.println(arrays.length);
        System.out.println(arrays[0].length);*/

        System.out.println(findNumberIn2DArray(arrays, 0));

    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix.length == 0) {
            return false;
        }

        int x = matrix[0].length;
        int y = matrix.length;
        boolean flag = false;

        LOOP:for (int i=0; i<x; i++) {

            for (int j=0; j<y; j++) {
                if (matrix[j][i] > target) {
                    y = j;
                    break;
                }
                if (matrix[j][i] == target) {
                    flag = true;
                    break LOOP;
                }
            }
        }

        return flag;

    }

}
